/**
 * @Title: PublicService.java
 * @author 7828wc
 * @date 2015年8月4日 上午10:57:31
 */
package com.onstar.cn.api;

import com.onstar.cn.api.framework.ClazzInjectUtils;
import com.onstar.cn.api.framework.annotation.Path;
import com.onstar.cn.api.framework.annotation.PathParams;
import com.onstar.cn.api.framework.annotation.RequestMapping;
import com.onstar.cn.common.log.LogManager;
import com.onstar.cn.common.util.Constants;
import com.onstar.cn.framework.network.entity.RequestEntity;
import com.onstar.cn.framework.utils.GsonHelper;
import com.onstar.cn.mag.publicService.DeviceInfoEntity;
import com.onstar.cn.mag.publicService.FeedbackEntity;
import com.onstar.cn.mag.publicService.PreferentialReqEntity;
import com.onstar.cn.mag.publicService.ReportEntity;
import com.onstar.cn.mag.publicService.ReqBannerEntity;
import com.onstar.cn.mag.publicService.SessionEntity;
import com.onstar.cn.mag.publicService.response.BroadcastEntity;
import com.onstar.cn.preferential.request.CommentUseReq;
import com.onstar.cn.preferential.request.MyDiscountReq;

import java.util.List;

/**
 * @ClassName: PublicService
 * @Description: Common restful mag interface
 * @author 7828wc
 * @date 2015年8月4日 上午10:57:31
 */
@Path("/msp/api/v3/public")
public class PublicService {

    public String serverURL;

    /**
     * @Description: TODO
     * @author 6335yz
     * @date 2015年8月25日 上午9:15:16
     */
    public PublicService(String serverURL) {
        this.serverURL = serverURL;
    }

    /**
     *
     * @Title: appVersion
     * @Description: Get lasest app version
     * @param @param requestEntity
     * @param @param osType
     * @param @return 设定文件
     * @return RequestEntity 返回类型
     * @throws
     */
    @RequestMapping("/app_version")
    public RequestEntity appVersion(RequestEntity requestEntity, String osType) {
        if (requestEntity == null) {
            requestEntity = new RequestEntity();
        }
        String url = ClazzInjectUtils.injectUrl(getClass(), "appVersion", requestEntity, osType);
        requestEntity.setUrl(serverURL + url + "?OSType=" + osType);
        return requestEntity;
    }

    /**
     *
     * @Title: report
     * @Description: Mag report
     * @param @param requestEntity
     * @param @return 设定文件
     * @return RequestEntity 返回类型
     * @throws
     */
    @RequestMapping("/report")
    public RequestEntity report(RequestEntity requestEntity, List<ReportEntity> reportList) {
        if (requestEntity == null) {
            requestEntity = new RequestEntity();
        }
        String url = ClazzInjectUtils.injectUrl(getClass(), "report", requestEntity, reportList);
        requestEntity.setUrl(serverURL + url);
        requestEntity.setBody(GsonHelper.toJson(reportList));
        return requestEntity;
    }

    /**
     * @Title: landingPage
     * @Description: Get landing page
     * @param @param requestEntity
     * @param @param OSType
     * @param @return 设定文件
     * @return RequestEntity 返回类型
     * @throws
     */
    @RequestMapping("/landing_page")
    public RequestEntity landingPage(RequestEntity requestEntity, String OSType) {
        if (requestEntity == null) {
            requestEntity = new RequestEntity();
        }
        String url = ClazzInjectUtils.injectUrl(getClass(), "landingPage", requestEntity, OSType);
        requestEntity.setUrl(serverURL + url + "?" + Constants.OS_TYPE + "=" + OSType);
        return requestEntity;
    }

    /**
     *
     * @Title: feedback
     * @Description: Feed back
     * @param @param requestEntity
     * @param @return 设定文件
     * @return RequestEntity 返回类型
     * @throws
     */
    @RequestMapping("/feedback")
    public RequestEntity feedback(RequestEntity requestEntity, FeedbackEntity entity) {
        if (requestEntity == null) {
            requestEntity = new RequestEntity();
        }
        String url = ClazzInjectUtils.injectUrl(getClass(), "feedback", requestEntity, entity);
        requestEntity.setUrl(serverURL + url);
        requestEntity.setBody(GsonHelper.toJson(entity));
        return requestEntity;
    }

    /**
     *
     * @Title: deviceInfo
     * @Description: Saving device info
     * @param @param requestEntity
     * @param @return 设定文件
     * @return RequestEntity 返回类型
     * @throws
     */
    @RequestMapping("/device_info")
    public RequestEntity deviceInfo(RequestEntity requestEntity, DeviceInfoEntity entity) {
        if (requestEntity == null) {
            requestEntity = new RequestEntity();
        }
        String url = ClazzInjectUtils.injectUrl(getClass(), "deviceInfo", requestEntity, entity);
        requestEntity.setUrl(serverURL + url);
        requestEntity.setBody(GsonHelper.toJson(entity));
        return requestEntity;
    }

    /**
     *
     * @Title: saveSession
     * @Description: TODO
     * @param @param requestEntity
     * @param @param entity
     * @param @return    设定文件
     * @return RequestEntity    返回类型
     * @throws
     */
    @RequestMapping("/save_session")
    public RequestEntity saveSession(RequestEntity requestEntity, SessionEntity entity) {
        if (requestEntity == null) {
            requestEntity = new RequestEntity();
        }
        String url = ClazzInjectUtils.injectUrl(getClass(), "saveSession", requestEntity, entity);
        requestEntity.setUrl(serverURL + url);
        requestEntity.setBody(GsonHelper.toJson(entity));
        LogManager.getInstance().d("session:" + requestEntity.getBody());
        return requestEntity;
    }


    /**
     * @Title: saveSession
     * @Description: TODO 获取Banner信息
     * @param @param requestEntity
     * @param @param entity
     * @param @return    设定文件
     * @return RequestEntity    返回类型
     * @throws
     */
    @RequestMapping("/banners")
    public RequestEntity getBanner(RequestEntity requestEntity, ReqBannerEntity entity) {
        if (requestEntity == null) {
            requestEntity = new RequestEntity();
        }
        String url = ClazzInjectUtils.injectUrl(getClass(), "getBanner", requestEntity, entity);
        requestEntity.setUrl(serverURL + url);
        requestEntity.setBody(GsonHelper.toJson(entity));
        return requestEntity;
    }
    /**
     * @Title: saveSession
     * @Description: TODO 获取Banner信息
     * @param @param requestEntity
     * @param @param entity
     * @param @return    设定文件
     * @return RequestEntity    返回类型
     * @throws
     */
    @RequestMapping("/banners")
    public RequestEntity getBanner(RequestEntity requestEntity, PreferentialReqEntity entity) {
        if (requestEntity == null) {
            requestEntity = new RequestEntity();
        }
        String url = ClazzInjectUtils.injectUrl(getClass(), "getBanner", requestEntity, entity);
        requestEntity.setUrl(serverURL + url);
        requestEntity.setBody(GsonHelper.toJson(entity));
        return requestEntity;
    }
    /**
     * @Title: saveSession
     * @Description: TODO 获取Banner信息
     * @param @param requestEntity
     * @param @param entity
     * @param @return    设定文件
     * @return RequestEntity    返回类型
     * @throws
     */
    @RequestMapping("/banners/mydiscount")
    public RequestEntity getBannerMyDiscount(RequestEntity requestEntity, PreferentialReqEntity entity) {
        if (requestEntity == null) {
            requestEntity = new RequestEntity();
        }
        String url = ClazzInjectUtils.injectUrl(getClass(), "getBannerMyDiscount", requestEntity, entity);
        requestEntity.setUrl(serverURL + url);
        requestEntity.setBody(GsonHelper.toJson(entity));
        return requestEntity;
    }

//    http://113.52.176.197:51611/msp/api/v3/indulgence/myindulgence/commentuse   put
//
//    request:{"vin":"123","make":"123","model":"123","year":"123","deviceType":"123","deviceOS":"123","languagePreference":"123","userID":"123","imgType":"123","versionCode":"123"}
//
//    response:
//            [{"imageUrl":"http://m-idt2.onstar.com.cn/emip/preferential/banner1@3x.png","title":"代驾","h5Url":"https://www.baidu.com"},{"imageUrl":"http://m-idt2.onstar.com.cn/emip/preferential/banner2@3x.png","title":"订餐","h5Url":"https://www.baidu.com"},{"imageUrl":"http://m-idt2.onstar.com.cn/emip/preferential/banner3@3x.png","title":"高尔夫","h5Url":"https://www.baidu.com"}]


    @RequestMapping("/indulgence/myindulgence/commentuse")
    public RequestEntity commentUse(RequestEntity requestEntity,CommentUseReq entity) {
        if (requestEntity == null) {
            requestEntity = new RequestEntity();
        }
        String url = ClazzInjectUtils.injectUrl(getClass(), "commentUse", requestEntity, entity);
        requestEntity.setUrl(serverURL + url);
        requestEntity.setBody(GsonHelper.toJson(entity));
        return requestEntity;
    }
//    http://113.52.176.197:51611/msp/api/v3/indulgence/myindulgence/hotactivity   put
//
//    request:{"vin":"123","make":"123","model":"123","year":"123","deviceType":"123","deviceOS":"123","languagePreference":"123","userID":"123","imgType":"123","versionCode":"123"}
//
//    response:
//            [{"imageUrl":"http://m-idt2.onstar.com.cn/emip/preferential/image1@3x.png","title":"泰国","h5Url":"https://www.baidu.com","expiredDate":"2016-04-20","fullImageUrl":"http://m-idt2.onstar.com.cn/emip/preferential/image1@3x.png"},{"imageUrl":"http://m-idt2.onstar.com.cn/emip/preferential/image2@3x.png","title":"韩国","h5Url":"https://www.baidu.com","expiredDate":"2016-05-20","fullImageUrl":"http://m-idt2.onstar.com.cn/emip/preferential/image2@3x.png"},{"imageUrl":"http://m-idt2.onstar.com.cn/emip/preferential/image3@3x.png","title":"海岛游","h5Url":"https://www.baidu.com","expiredDate":"2016-06-20","fullImageUrl":"http://m-idt2.onstar.com.cn/emip/preferential/image3@3x.png"},{"imageUrl":"http://m-idt2.onstar.com.cn/emip/preferential/image4@3x.png","title":"沙巴","h5Url":"https://www.baidu.com","expiredDate":"2016-07-20","fullImageUrl":"http://m-idt2.onstar.com.cn/emip/preferential/image4@3x.png"}]

    @RequestMapping("/contents/mydiscount")
    public RequestEntity getMyDiscount(RequestEntity requestEntity, MyDiscountReq entity) {
        if (requestEntity == null) {
            requestEntity = new RequestEntity();
        }
        String url = ClazzInjectUtils.injectUrl(getClass(), "getMyDiscount", requestEntity, entity);
        requestEntity.setUrl(serverURL + url);
        requestEntity.setBody(GsonHelper.toJson(entity));
        return requestEntity;
    }

    /**
     *
     * @Title: broadcast
     * @Description: 广播信息列表
     * @param @param requestEntity
     * @param @param broadcastEntity
     * @param @return    设定文件
     * @return RequestEntity    返回类型
     * @throws
     */
    @RequestMapping("/broadcasts")
    public RequestEntity broadcast(RequestEntity requestEntity, BroadcastEntity broadcastEntity) {
        if (requestEntity == null) {
            requestEntity = new RequestEntity();
        }
        String url = ClazzInjectUtils.injectUrl(getClass(), "broadcast", requestEntity, broadcastEntity);
        requestEntity.setUrl(serverURL + url);
        requestEntity.setBody(GsonHelper.toJson(broadcastEntity));
        return requestEntity;
    }

    /**
     *
     * @Title: BroadcastById
     * @Description: 广播信息详情
     * @param @param entity
     * @param @param id
     * @param @return    设定文件
     * @return RequestEntity    返回类型
     * @throws
     */
    @RequestMapping("/broadcasts/{id}")
    public RequestEntity BroadcastById(RequestEntity entity, @PathParams(value = "id") String id, String versionCode) {
        if (entity == null) {
            entity = new RequestEntity();
        }
        String url = ClazzInjectUtils.injectUrl(getClass(), "BroadcastById", entity, id, versionCode);
        entity.setUrl(serverURL + url + "?versionCode=" + versionCode);
        return entity;
    }

    /**
     *
     * @Title: contents
     * @Description: 别克关怀
     * @param @param entity
     * @param @param osType
     * @param @param category
     * @param @return    设定文件
     * @return RequestEntity    返回类型
     * @throws
     */
//	@RequestMapping("/contents")
//	public RequestEntity contents(RequestEntity entity, String osType,String category){
//		if (entity == null) {
//			entity = new RequestEntity();
//		}
//		String url = ClazzInjectUtils.injectUrl(getClass(), "contents", entity, osType, category);
//		entity.setUrl(serverURL + url + "?osType=" + osType + "&category=" + category);
//		return entity;
//	}
    @RequestMapping("/contents")
    public RequestEntity contents(RequestEntity entity, String osType, String category, String versionCode) {
        if (entity == null) {
            entity = new RequestEntity();
        }
        String url = ClazzInjectUtils.injectUrl(getClass(), "contents", entity, osType, category, versionCode);
        entity.setUrl(serverURL + url + "?osType=" + osType + "&category=" + category + "&versionCode=" + versionCode);
        return entity;
    }
//	@RequestMapping("/contents/{contentID}")
//	public RequestEntity getContentBycontentID(RequestEntity entity,@PathParams(value = "contentID") String contentID){
//		if (entity == null) {
//			entity = new RequestEntity();
//		}
//		String url = ClazzInjectUtils.injectUrl(getClass(), "getContentBycontentID", entity,contentID);
//		entity.setUrl(serverURL + url );//+ "?category="+category
//		return entity;
//	}

    @RequestMapping("/contents/{contentID}")
    public RequestEntity getContentBycontentID(RequestEntity entity,
                                               @PathParams(value = "contentID") String contentID, String category, String versionCode) {
        if (entity == null) {
            entity = new RequestEntity();
        }
        String url = ClazzInjectUtils.injectUrl(getClass(), "getContentBycontentID", entity, contentID, category, versionCode);
//		url = url.replaceFirst("v1", "v2");
        url = serverURL + url + "?category=" + category + "&versionCode=" + versionCode;
        entity.setUrl(url);//+ "?category="+category
        return entity;
    }

    @RequestMapping("/contents/{contentID}")
    public RequestEntity getHelpByContentID(RequestEntity entity,
                                            @PathParams(value = "contentID") String contentID) {
        if (entity == null) {
            entity = new RequestEntity();
        }
        String url = ClazzInjectUtils.injectUrl(getClass(), "getHelpByContentID", entity, contentID);
        url = serverURL + url;
        entity.setUrl(url);
        return entity;
    }

    @RequestMapping("/alert_duration")
    public RequestEntity alertDuration(RequestEntity entity) {
        if (entity == null) {
            entity = new RequestEntity();
        }
        String url = ClazzInjectUtils.injectUrl(getClass(), "alertDuration", entity);
        entity.setUrl(serverURL + url);//+ "?category="+category
        return entity;
    }
//    &versionCode=28
    @RequestMapping("/contents")
    public RequestEntity queryHelpList(RequestEntity entity, String category ,String versionCode) {
        if (entity == null) {
            entity = new RequestEntity();
        }
        String url = ClazzInjectUtils.injectUrl(getClass(), "queryHelpList", entity, category,versionCode);
        entity.setUrl(serverURL + url + "?category=" + category+"&versionCode="+versionCode);//+ "?category="+category
        return entity;
    }
    @RequestMapping("/contents")
    public RequestEntity queryHelpList(RequestEntity entity, String category ) {
        if (entity == null) {
            entity = new RequestEntity();
        }
        String url = ClazzInjectUtils.injectUrl(getClass(), "queryHelpList", entity, category);
        entity.setUrl(serverURL + url + "?category=" + category);//+ "?category="+category
        return entity;
    }

    @RequestMapping("/feedback")
    public RequestEntity saveFeedback(RequestEntity entity) {
        if (entity == null) {
            entity = new RequestEntity();
        }
        String url = ClazzInjectUtils.injectUrl(getClass(), "saveFeedback", entity);
        entity.setUrl(serverURL + url);//+ "?category="+category
        return entity;
    }

    @RequestMapping("/cache")
        public RequestEntity clearCache(RequestEntity entity) {
        if (entity == null) {
            entity = new RequestEntity();
        }
        String url = ClazzInjectUtils.injectUrl(getClass(), "clearCache", entity);
        entity.setUrl(serverURL + url);//+ "?category="+category
        return entity;
    }
}
